#include <stdio.h>
#include <math.h>
#include <time.h>
#include "interval_tree.h"
#include "templatestack.h"

class MyInterval : public Interval
{
public:
  float _low;
  float _high;
  MyInterval(float low, float high)
    :_low(low), _high(high){}
  float GetLowPoint() const{return _low;}
  float GetHighPoint()const{return _high;}
};

int main()
{
  float low;
  float high;

  IntervalTree intervalTree;
  int count = 1000000;
  int domain = 1;
  printf("Inserting %i nodes into [0,%i].\n", count, domain);
  for(int i=0; i<count; i++)
  {
    low = (float)rand()/(float)RAND_MAX;
	high = ((float)rand()/(float)RAND_MAX) + low;
	
	intervalTree.Insert(new MyInterval(low,high));
	//printf("Added: [%i,%i]\n", low,high);
	if(!(i%25000)){printf("*");fflush(0);}
  }
  printf("\n");
  
  low = domain * 0.4f;
  high = domain * 0.5f;//10% of the domain is being tested
  printf("Enumerating intervals between %f and %f\n", low, high);
  TemplateStack<MyInterval*> *results = (TemplateStack<MyInterval*>*)intervalTree.Enumerate(low,high);

  printf("%i intervals found.\n", results->Size());
  //for(int i=0; i< results->Size(); i++)
  //	  printf("[%f,%f]\n", (*results)[i]->GetLowPoint(), (*results)[i]->GetHighPoint());

  return 0;
}
